package edu.gdut.tiantian.utils;
//自定义类型转换器(SpringMVC)
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

public class StringToDateConverter implements Converter<String,Date>{

	@Override
	public Date convert(String source) {
		DateFormat format = null;
		try {
			if(StringUtils.isEmpty(source)) {
				throw new NullPointerException("请输入日期");
			}
			format = new SimpleDateFormat("yyyy-MM-dd");
			Date date = format.parse(source);
			return date;  
		}catch(Exception e) {
			throw new RuntimeException("日期格式有误");
		}
	}
	
}
